//
//  OpSelectedAdressController.m
//  LoveFreshBeeReplica
//
//  Created by skywalker on 16/12/31.
//  Copyright © 2016年 斯芬克斯. All rights reserved.
//

#import "OpSelectedAdressController.h"
#import "UIBarButtonItem+Button.h"
#import "OpScanViewController.h"
#import "OpSearchViewController.h"

@interface OpSelectedAdressController ()
@property(nonatomic,strong)UILabel *titleLabel;

@end

@implementation OpSelectedAdressController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self buildNavigationBar];
    
}
-(void)buildNavigationBar{

    self.navigationController.navigationBar.barTintColor = GeneralColor;
    self.navigationItem.leftBarButtonItem= [UIBarButtonItem barButtonItem:@"扫一扫" image:@"icon_black_scancode" target:self action:@selector(LeftItemButtonClick) type:LeftItemButton];
     self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItem:@"搜索" image:@"icon_search" target:self action:@selector(rightBarButtonClick) type:RightItemButton];
    
    UISearchBar * search=[[UISearchBar alloc]init];
    self.navigationItem.titleView=search;
  
}
#pragma mark -自定义titleView
#warning 自定义titleView未完成
-(UIView *)buildTitleView{
    
    UIView * titleView=[[UIView alloc]init];
   

    
    UIButton * button =[UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"配送至" forState: UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [button setBackgroundColor:COLOR(254, 247, 9, 1)];
    [button setUserInteractionEnabled:YES];
    [button.layer setBorderColor:[UIColor blackColor].CGColor];
    [button.layer setBorderWidth:1];
    [button.layer setShadowOpacity:0.8];
    [button.layer setShadowOffset:CGSizeMake(1, 2)];
    [button sizeToFit];
    [titleView addSubview:button];
    
    self.titleLabel=[[UILabel alloc]init];
    [self.titleLabel setText:@"你在哪里呀"];
    [self.titleLabel setTextColor:[UIColor blackColor]];
    [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
    [self.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [titleView addSubview:self.titleLabel];
    
    UIButton *triangle =[UIButton buttonWithType: UIButtonTypeCustom];
    [triangle setBackgroundImage:[UIImage imageNamed:@"allowBlack"] forState:UIControlStateNormal];
    [triangle addTarget:self action:@selector(providePositionMessage) forControlEvents:UIControlEventTouchUpInside];
    [triangle setBackgroundColor:COLOR(254, 247, 9, 1)];
    [titleView addSubview:triangle];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.rightMargin.equalTo(self.titleLabel).mas_offset(3);
        make.left.equalTo(titleView).mas_offset(130);
        make.height.mas_offset(10);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(15);
        make.left.equalTo(button).mas_offset(3);
        make.right.equalTo(triangle).mas_offset(2);
    }];
    [triangle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self.titleLabel);
        make.left.equalTo(self.titleLabel).mas_offset(3);
        make.right.equalTo(titleView).mas_offset(130);
    }];
    titleView.center=self.navigationController.navigationBar.center;
    return titleView;
}
#pragma mark -扫一扫，搜索按钮事件
- (void)LeftItemButtonClick{
    OpScanViewController * scan=[[OpScanViewController alloc]init];
    [self.navigationController pushViewController:scan animated:NO];
    
}
- (void)rightBarButtonClick{
    OpSearchViewController * search=[[OpSearchViewController alloc]init];
    [self.navigationController pushViewController:search animated:NO];
}
#pragma mark -配送至选项
-(void)providePositionMessage{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
